package com.example.test.util;

import java.io.*;
import java.net.Socket;

public class Client {

    public static void main(String[] args) throws IOException, InterruptedException {
        try {
            Socket socket = new Socket("127.0.0.1", 9999);
            InputStream input = socket.getInputStream();
            OutputStream output = socket.getOutputStream();
            String msg = "hello";
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(output));
            bufferedWriter.write(msg);
            bufferedWriter.flush();
            socket.shutdownOutput();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input));
            String str = bufferedReader.readLine();
            if(str!=null){
                System.out.println(str);
            }
            Thread.sleep(10000);
            socket.close();
            System.out.println("disconnected...");
        }catch (IOException e){
            System.out.println(e.getMessage());
        }

    }


}
